package ua.cn.store.impl;

import java.util.List;

import ua.cn.store.domain.Book;
import ua.cn.store.domain.Genres;
import ua.cn.store.service.GeneralServiceException;
import ua.cn.store.service.IBookService;

public class BookServiceImpl extends GenericServiceImpl<Book> implements IBookService{

	public BookServiceImpl() {
		super(Book.class);		
	}

	@Override
	public List<Book> getBookByAuthor(String author)
			throws IllegalArgumentException, GeneralServiceException {
		if (author == null){
			throw new IllegalArgumentException("Book author is null");
		}
		return executeQuery("Book.getBookByAuthor", true, false, author);
	}

	@Override
	public List<Book> getBookByGenre(Genres genre)
			throws IllegalArgumentException, GeneralServiceException {
		if (genre == null){
			throw new IllegalArgumentException("Book genre is null");
		}
		return executeQuery("Book.getBookByGenre",true, false, genre);
	}

	@Override
	public List<Book> getBookByName(String name)
			throws IllegalArgumentException, GeneralServiceException {
		if (name == null){
			throw new IllegalArgumentException("Book name is null");
		}
		return executeQuery("Book.getBookByName", true, false, name);
	}

	@Override
	protected void beforeEntityAddUpdate(Book obj)
			throws GeneralServiceException {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void beforeEntityDelete(Book obj) throws GeneralServiceException {
		// Delete Comments of Book
		executeUpdateQuery("DeleteByBook", true, obj.getId()); 
		
	}

	
	

}
